var express = require('express');
var router = express.Router();
var mongo = require('mongodb');
const db =require('../database/db.js');
const noticeControl = require('../bin/control/noticeControl')

router.get('/editor', function(req, res, next) { // 文章的编辑页
  var _id = req.query.id;
  console.log(_id)
  noticeControl.findOneNotice(_id,(db)=>{
    res.render('noticeEditor',{db:JSON.stringify(db)});
  })
 });


 router.get("/noticeAdd",(req,res)=>{ //文章增加页
  res.render('noticeAdd');
})


router.get('/list', function(req, res, next) { //文章列表
  var page = parseInt(req.query.page);
  if(!page){
    page = 0;
  }
 db.count('articles',function(number){
  db.find_num('notice',{},10,page,function(dbs){
    res.render('noticeList',{data:JSON.stringify(dbs),data_h:dbs,number:number,page:page});
  });
 })
});
module.exports = router;
